﻿using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Windows.Input;
namespace CoreModule
{
    /// <summary>
    /// 患者信息
    /// </summary>
    /// 

    public class PatientInfo {
        /// <summary>
        /// 呵呵
        /// </summary>
        /// 
        [NotMapped]
        public static PatientInfo Instance { get; set; }
         
        /// <summary>
        /// 
        /// </summary>
        /// 
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Key]
        public int Id { get; set; }
        /// <summary>
        /// 姓名
        /// </summary>
        [System.ComponentModel.DataAnnotations.StringLength(50)]
        public string PatientName { get; set; } = string.Empty;

        [NotMapped]

        public string PatientNameString
        {
            get
            {
                if (string.IsNullOrWhiteSpace(PatientName))
                {
                    return PatientName;
                }
                if (PatientName.Length>4)
                {
                    return PatientName.Substring(0, 4) + "...";
                }
                else
                {
                    return PatientName;
                }
            }
            set
            {

            }
        }
        /// <summary>
        /// 身份证
        /// </summary>
        /// 
        [System.ComponentModel.DataAnnotations.StringLength(50)]
        public string IdCard { get; set; } = string.Empty;
        /// <summary>
        /// 社保卡
        /// </summary>
        /// 
        [System.ComponentModel.DataAnnotations.StringLength(50)]
        public string SocialCard { get; set; } = string.Empty;
        /// <summary>
        /// 用户标识
        /// </summary>
        /// 
        [System.ComponentModel.DataAnnotations.StringLength(50)]
        public string WdCode { get; set; } = string.Empty;

        [NotMapped]
        public string WdCodeString
        {
            get
            {
                if (string.IsNullOrWhiteSpace(WdCode))
                {
                    return WdCode;
                }
                if (WdCode.Length>18)
                {
                    return WdCode.Substring(0, 18) + "...";
                }
                else
                {
                    return WdCode;
                }
            }
            set
            {

            }
        }
        /// <summary>
        /// 年龄
        /// </summary>
        public int Age { get; set; } =0;
        [NotMapped]
        public string AgeString { get
            {
                return Age > 0 ? Age.ToString() : string.Empty;
            } }

      
        [NotMapped]
        public string AgeStringFormat
        {
            get
            {
                return Age > 0 ? Age.ToString() +"岁": string.Empty;
            }
            set { }
        }
        /// <summary>
        /// 性别
        /// </summary>
        public SexKind Sex { get; set; } = SexKind.None;
        [NotMapped]
        public string SexString
        {
            get
            {
                switch (Sex)
                {
                    case SexKind.None:
                        return "-";
                    case SexKind.Male:
                        return "男";
                    case SexKind.Female:
                        return  "女";
                    default:
                        return string.Empty;
                }

            }
            set { }
        }
        /// <summary>
        /// 
        /// </summary>
        public bool IsValid 
        { 
            get
            {
                return !string.IsNullOrWhiteSpace(this.PatientName)
                    || !string.IsNullOrWhiteSpace(this.SocialCard)
                    || !string.IsNullOrWhiteSpace(this.IdCard)
                    || !string.IsNullOrWhiteSpace(this.WdCode);
            }
            set
            {
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// 
        [System.ComponentModel.DataAnnotations.StringLength(200)]
        public string Height { get; set; } = string.Empty;
        /// <summary>
        /// 体重 
        /// </summary>
        /// 
        [System.ComponentModel.DataAnnotations.StringLength(200)]
        public string Weight { get; set; } = string.Empty;
        /// <summary>
        /// 手机号
        /// </summary>
        /// 
        [System.ComponentModel.DataAnnotations.StringLength(50)]
        public string MobilePhone { get; set; } = string.Empty;
        /// <summary>
        /// 
        /// </summary>
        /// 
        public List<MeasurementResultInfo> MeasurementResultInfos { get; set; } = new List<MeasurementResultInfo>();


        /// <summary>
        /// 
        /// </summary>
        public AgeGroup AgeGroup { get; set; } = AgeGroup.None;

        public void UpdateAgeGroup()
        {
            this.AgeGroup = CoreModule.Extension.ToAgeGroup(this.Age);
        }

        [NotMapped]
        public string AgeGroupDescription { get {
                return AgeGroup.GetDescription();
            }set { } }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime { get; set; }= DateTime.Now;
        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdateTime { get; set; } = DateTime.Now;
    }
}
